package com.myjavalab.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
	public static void viewUserTable(Connection con, String dbName)
			throws SQLException {
		Statement stmt = null;
		String query = "select user_id, user_name, user_password, user_email from "
				+ dbName + ".user";
		try {
			stmt = con.createStatement();
			ResultSet rs = stmt.executeQuery(query);
			while (rs.next()) {
				String userName = rs.getString("user_name");
				int userID = rs.getInt("user_id");
				String userEmail = rs.getString("user_email");
				String userPassword = rs.getString("user_password");
				System.out.println(userID + "\t" + userName + "\t" + userEmail
						+ "\t" + userPassword);
			}
		} catch (SQLException e) {
			System.out.print(e);
		} finally {
			if (stmt != null) {
				stmt.close();
			}
		}
	}

	public static void main(String[] args) throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
		JdbcConnection con = new JdbcConnection();
		viewUserTable(con.getConnection(), "j2datastore");
	}
}
